import { KKHandler, KKP2D, KKTransformer } from '@coldcloude/kakera';
import { _decorator, Component } from 'cc';
const { ccclass } = _decorator;

@ccclass('MapController')
export class MapController extends Component {
    //move
    moveViewHandler:KKHandler<KKP2D>;
    moveView(delta:KKP2D){
        if(this.moveViewHandler){
            this.moveViewHandler(delta);
        }
    }
    onMoveView(handler:KKHandler<KKP2D>){
        this.moveViewHandler = handler;
    }
    //moveTo
    viewAtHandler:KKHandler<KKP2D>;
    viewAt(target:KKP2D){
        if(this.viewAtHandler){
            this.viewAtHandler(target);
        }
    }
    onViewAt(handler:KKHandler<KKP2D>){
        this.viewAtHandler = handler;
    }
    //roundToGrid
    roundToGridTransformer:KKTransformer<KKP2D,KKP2D>
    roundToGrid(src:KKP2D){
        if(this.roundToGridTransformer){
            return this.roundToGridTransformer(src);
        }
        else{
            return src;
        }
    }
    onRoundToGrid(transformer:KKTransformer<KKP2D,KKP2D>){
        this.roundToGridTransformer = transformer;
    }
}
